using System.Collections.Generic;
using BuildWheel;
using UnityEngine;
using UnityEngine.UIElements;
using BaseInspector = UI.Inspector.BaseInspector;

public class Inspector : SingletonBehaviour<Inspector>
{
    private UIDocument uiroot;
    public Dictionary<string, BaseInspector> typeDic = new Dictionary<string, BaseInspector>();
    private VisualElement inspector;
    private VisualElement resElement;

    private void Awake()
    {
        uiroot = GetComponent<UIDocument>();
        // 更安全的查询方式（分步查询）
        inspector = uiroot.rootVisualElement.Q<VisualElement>("Inspector");

        new ResInspector(inspector, transform);
        new GameObjectInspector(inspector, transform);
    }

    void Show(string key)
    {
        foreach (var item in typeDic)
        {
            if(item.Key == key)
            {
                item.Value.Show();
            }
            else
            {
                item.Value.Hide();
            }
        }
    }
    
    private File selectFile;
    private GameObject selectGo;

    public void Ref(File file)
    {
        if (selectFile == file) return;
        selectFile = file;
        Show("Res");
        typeDic["Res"].Ref(file);
    }

    public void Ref(GameObject go)
    {
        if (selectGo == go) return;
        selectGo = go;
        Show("GameObject");
        typeDic["GameObject"].Ref(go);
    }
}